package com.ruoyi.web.controller.api;


import com.ruoyi.cat.domain.CatBannerTable;
import com.ruoyi.cat.domain.CatBaseimgTable;
import com.ruoyi.cat.domain.CatNoticeTable;
import com.ruoyi.cat.service.ICatBannerTableService;
import com.ruoyi.cat.service.ICatBaseimgTableService;
import com.ruoyi.cat.service.ICatNoticeTableService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.IpRegion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "api-轮播图相关接口")
@RestController
@RequestMapping("/api/carousel")
public class CarouselController extends BaseController {


    @Autowired
    private ICatBannerTableService catBannerTableService;


    @Autowired
    private ICatBaseimgTableService catBaseimgTableService;


    @Autowired
    private ICatNoticeTableService catNoticeTableService;

    @ApiOperation("api-获取轮播图列表")
    @GetMapping("/list")
    public TableDataInfo list(CatBannerTable catBannerTable)
    {
        startPage();
        catBannerTable.setType(1L);
        List<CatBannerTable> list = catBannerTableService.selectCatBannerTableList(catBannerTable);
        return getDataTable(list);
    }


    @ApiOperation("api-获取基础图片列表")
    @GetMapping("/getBaseimgList")
    public TableDataInfo getBaseimgList(CatBaseimgTable catBaseimgTable)
    {
        startPage();
        List<CatBaseimgTable> list = catBaseimgTableService.selectCatBaseimgTableList(catBaseimgTable);
        return getDataTable(list);
    }


    @ApiOperation("api-获取公告列表")
    @GetMapping("/getNoticeTable")
    public TableDataInfo getNoticeTable(CatNoticeTable catNoticeTable)
    {
        startPage();
        List<CatNoticeTable> list = catNoticeTableService.selectCatNoticeTableList(catNoticeTable);
        return getDataTable(list);
    }

    @ApiOperation("api-根据id获取详情")
    @GetMapping("/getNoticeTableById")
    public AjaxResult getNoticeTable(Long id)
    {
        CatNoticeTable list = catNoticeTableService.selectCatNoticeTableById(id);
        return success(list);
    }

/*    String ip = "39.70.41.77";
    IpRegion location = parseIpLocation(ip);
        System.out.println("省份：" + location.getProvince());
        System.out.println("城市：" + location.getCity());*/

    @ApiOperation("api-测试")
    @GetMapping("/getNoticeTable1")
    public AjaxResult getNoticeTable1(CatNoticeTable catNoticeTable)
    {
        String ip = "39.70.41.77";
        IpRegion location = IpAddressUtil.parseIpLocation(ip);
        System.out.println("省份：" + location.getProvince());
        System.out.println("城市：" + location.getCity());
        return success();
    }



}
